import * as api from '../../../api/projectManage';

export default {
  namespace: 'packing',

  state: {
    uploadData: [],
  },

  effects: {
    * fetch({ payload, callback }, { call, put }) {
      const response = yield call(api.bankList, payload);
      yield put({
        type: 'fetchData',
        payload: response.msg,
      });
      if (callback) callback();
    },
    * edit({ payload, callback }, { call, put }) {
      const response = yield call(api.edit, payload);
      if (callback) callback(response);
    },
    * put({ payload, callback }, { call, put }) {
      const response = yield call(api.packing, payload);
      if (callback) callback(response);
    },
    * getDesc({ payload, callback }, { call, put }) {
      const response = yield call(api.Detail, payload);
      yield put({
        type: 'descData',
        payload: response.msg,
      });
      if (callback) callback(response);
    },
    * merchantList({ payload, callback }, { call, put }) {
      const response = yield call(api.merchantList, payload);
      yield put({
        type: 'merchantLists',
        payload: response.msg,
      });
      if (callback) callback(response);
    },
    * upload({ payload, callback }, { call, put }) {
      const response = yield call(api.uploadFile, payload);
      yield put({
        type: 'uploadLists',
        payload: response.msg,
      });
      if (callback) callback(response);
    },
    * uploadData({ payload, callback }, { call, put }) {
      console.log(payload);
      yield put({
        type: 'setUploadData',
        payload: payload,
      });
    },
  },

  reducers: {
    fetchData(state, { payload }) {
      return {
        ...state,
        fetchData: payload,
      };
    },
    descData(state, { payload }) {
      return {
        ...state,
        descDatas: payload,
      };
    },
    merchantLists(state, { payload }) {
      return {
        ...state,
        merchantLists: payload,
      };
    },
    uploadLists(state, { payload }) {
      return {
        ...state,
        uploadLists: payload,
      };
    },
    setUploadData(state, { payload }) {
      state.uploadData = payload;
      return {
        ...state,
      };
    },
  },
};
